var n=0,m1,m2;
var person=Array(200).fill(0);
var vis=Array(200).fill(0);
var vis1=Array(200).fill(0);
var map=new Map();

document.querySelector('#excel').onchange = function (e) {
	n=m1=m2=0;
    let file = e.target.files[0];
    readWorkbookFromLocalFile(file, function(workbook) {
      readWorkbook(workbook);
    });
}
function readWorkbookFromLocalFile(file, callback) {
    var reader = new FileReader();
    reader.onload = function(e) {
      	var data = e.target.result;
      	var workbook = XLSX.read(data, {type: 'binary'});
      	console.log(workbook);
      	if(callback) callback(workbook);
    };
    reader.readAsBinaryString(file);
}
function readWorkbook(workbook){
    var sheetNames=workbook.SheetNames;
    var worksheet=workbook.Sheets[sheetNames[0]];
    var csv=XLSX.utils.sheet_to_csv(worksheet);
	var rows=csv.split('\n');
	var header=rows[0].split(',');
	var name_pos;
	for(var i=0;i<header.length;i++){
		if(header[i].indexOf('姓名')!=-1||header[i].indexOf('名字')!=-1) name_pos=i;
	}
	console.log(name_pos);
	for(var i=1;i<rows.length;i++){
		var tmp=rows[i].split(',');
		var name=tmp[name_pos];
		if(!map.has(name)){
			map.set(name,1);
			person[n++]=name;
		}
	}
	load();
	console.log(person);
}
function load(){
	for(var i=0;i<n;i++){
		var tmp=localStorage.getItem('vis'+String(i));
		if(tmp!=null) vis[i]=1; 
	}
	localStorage.setItem('total_of_people',n);
	localStorage.setItem('rest',n);
	for(var i=0;i<n;i++) localStorage.setItem('person'+String(i),person[i]);
	$('.tip').html('当前还有'+String(n)+'人未中奖');
}